package com.forgenet.message;

import com.baidu.bjf.remoting.protobuf.MessageGenerator;
import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import com.sparrow.common.util.PackageUtil;

import java.io.File;
import java.util.Set;

public class MessageGenMain {

    public static void main(String[] args) throws Exception {
        Set<Class<?>> classes = PackageUtil.scanClass("com.forgenet.message", classMetadata -> classMetadata.hasAnnotation(ProtobufClass.class.getName()));
        String classPath = MessageGenMain.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
        File targetDir = new File(classPath).getParentFile(); // 这是 target 目录
        File moduleRoot = targetDir.getParentFile();          // 向上一层，拿到模块根目录
        System.out.println("模块根目录: " + moduleRoot.getAbsolutePath());
        new MessageGenerator().generate(classes, moduleRoot.getAbsolutePath());
    }

}
